package com.jilian.mydemo.modul.user.activity;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.jilian.mydemo.MyApplication;
import com.jilian.mydemo.R;
import com.jilian.mydemo.base.BaseActivity;
import com.jilian.mydemo.base.BaseDto;
import com.jilian.mydemo.modul.main.ui.MainActivity;
import com.jilian.mydemo.modul.main.ui.WelcomeActivity;
import com.jilian.mydemo.modul.user.viewmodel.UserViewModel;
import com.jilian.mydemo.utils.ToastUitl;

/**
 * 审核成功
 */
public class ReviewSuccessActivity extends BaseActivity {
    private TextView tvOk;
    private UserViewModel viewModel;

    @Override
    protected void createViewModel() {
        viewModel = ViewModelProviders.of(this).get(UserViewModel.class);
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyApplication.removeActivity(this);
    }

    @Override
    public int intiLayout() {

        return R.layout.activity_reviewsuccess;
    }

    @Override
    public void initView() {
        setNormalTitle(getIntent().getStringExtra("title"), v -> finish());

        tvOk = (TextView) findViewById(R.id.tv_ok);
    }

    @Override
    public void initData() {
        MyApplication.clearSpecifyActivities(new Class[]{WelcomeActivity.class});
    }

    @Override
    public void initListener() {
        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //如果是实名认证 则需要修改下实名的接口 状态
                //      intent.putExtra("title", "实名认证");
                if ("实名认证".equals(getIntent().getStringExtra("title"))) {
                    showLoadingDialog();
                    viewModel.clicked();
                    viewModel.getClickedliveData().observe(ReviewSuccessActivity.this, new Observer<BaseDto>() {
                        @Override
                        public void onChanged(@Nullable BaseDto dto) {
                            hideLoadingDialog();
                            if (dto.isSuccess()) {
                                startActivity(new Intent(ReviewSuccessActivity.this, MainActivity.class));
                                finish();
                            } else {
                                ToastUitl.showImageToastTips(dto.getMsg());
                            }

                        }
                    });
                } else {
                    startActivity(new Intent(ReviewSuccessActivity.this, MainActivity.class));
                    finish();
                }


            }
        });
    }
}
